package com.tpod.taxi.view;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

import com.tpod.taxi.R;

@SuppressWarnings("deprecation")
public class MainActivity extends TabActivity {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_layout);
		initTabs();
	}

	private void initTabs() {
		addTab(R.string.taxi, R.drawable.tab_icon_taxi_selector, TabTaxi.class);
		addTab(R.string.truck_taxi, R.drawable.tab_icon_truck_selector,
				TabTruck.class);
		addTab(R.string.hot_line, R.drawable.tab_icon_hotline_selector,
				TabHotLine.class);
	}

	/**
	 * Add tab item
	 * 
	 * @param labelResId
	 * @param iconDrawableResId
	 * @param contentClass
	 */
	private void addTab(int labelResId, int iconDrawableResId,
			Class<?> contentClass) {
		TabHost tabHost = getTabHost();
		Intent intent = new Intent(this, contentClass);
		TabHost.TabSpec spec = tabHost
				.newTabSpec("tab" + getString(labelResId));

		View tabIndicatorView = LayoutInflater.from(this).inflate(
				R.layout.tab_widget_item_layout, getTabWidget(), false);
		TextView title = (TextView) tabIndicatorView.findViewById(R.id.title);
		title.setText(getString(labelResId));
		ImageView icon = (ImageView) tabIndicatorView.findViewById(R.id.icon);
		icon.setImageResource(iconDrawableResId);

		spec.setIndicator(tabIndicatorView);
		spec.setContent(intent);
		tabHost.addTab(spec);
	}

}
